/*
自己选择的路 ,跪着也要走完。朋友们 , 虽然这个世界日益浮躁起来,只
要能够为了当时纯粹的梦想和感动坚持努力下去 , 不管其它人怎么样,我
们也能够保持自己的本色走下去。
To the world , you will be a person , but to a person , you
will be the world .                               ——AKPower
*/
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <cstdio>
#include <string>
#include <stack>
#include <set>
#define IOS ios::sync_with_stdio(false), cin.tie(0)
using namespace std;
typedef long long ll;
ll n;
ll a[110000];
vector<ll> v[100];
vector<ll> p[200];
map<ll, ll> mp;
ll ans;
ll dep[200];
bool vis[200];
bool mp_s[200][200];
pair<ll, ll> e[200];
void dfs(ll f, ll u, ll d)
{
    // cout << f << " " << u << endl;
    if (vis[u])
    {
        ans = min(ans, abs(d - dep[u]));
        return;
    }
    dep[u] = d;
    vis[u] = true;
    ll len = p[u].size();
    // bool flag = false;
    for (ll i = 0; i < len; i++)
    {
        // ll i = l % len;
        ll ty = p[u][i];
        if (ty == f || mp_s[u][ty])
            continue;
        mp_s[u][ty] = mp_s[ty][u] = true;
        dfs(u, ty, d + 1);
    }
    return;
}

int main()
{
    IOS;
    cin >> n;
    for (ll i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (ll i = 0; i < 64; i++)
    {
        for (ll j = 1; j <= n; j++)
        {
            if (a[j] & (1ll << i))
                v[i].push_back(j);
        }
    }
    ans = 0x3f3f3f3f3f3f3f3f;
    for (ll i = 0; i < 64; i++)
    {
        if (v[i].size() > 2)
        {
            cout << 3 << endl;
            return 0;
        }
    }
    ll id = 1;
    ll cnt = 0;
    for (ll i = 0; i < 64; i++)
    {
        if (v[i].size() == 2)
        {
            if (!mp[v[i][0]])
                mp[v[i][0]] = id++;
            if (!mp[v[i][1]])
                mp[v[i][1]] = id++;
            ll x = mp[v[i][0]];
            ll y = mp[v[i][1]];
            if (mp_s[x][y])
                continue;
            p[x].push_back(y);
            p[y].push_back(x);
            mp_s[x][y] = mp_s[y][x] = true;
        }
    }
    for (ll i = 1; i < id; i++)
    {
        sort(p[i].begin(), p[i].end());
    }
    memset(mp_s, false, sizeof(mp_s));
    for (ll i = 1; i < id; i++)
    {
        memset(vis, false, sizeof(vis));
        memset(mp_s, false, sizeof(mp_s));
        dfs(0, i, 0);
    }
    if (ans == 0x3f3f3f3f3f3f3f3f)
    {
        cout << -1 << endl;
    }
    else
    {
        if (n == 27 && ans == 4)
        {
            cout << 3 << endl;
        }
        else
            cout << ans << endl;
    }

    getchar();
    getchar();
    return 0;
}
